<?php
/* ========== ########## ========== ########## ========== ########## ========== */
/*                                                                              */
/*   WHMCS v4.1.2 NULLED R4 by FLIPMODE  [ BAD SYNTAX ]                         */
/*                                                                              */
/*                             INTERNAL BAD SYNTAX NULLED VERSION: 2.5.9.6 R4   */
/*                                                                              */
/*   ALL files have been analysed, cleaned and nulled of:                       */
/*     - Call Backs  (100%)                                                     */
/*     - Link Backs (95%)                                                       */
/*     - Licensing  (100%)                                                      */
/*     - Remote Links + URL's                                                   */
/*                                                                              */
/*   WHMCS v4.1.2 RELEASED: 4th November 2009                                   */
/*    -> FIRST v4.1.2 NULL R1: 19th November 2009                               */
/*    -> UPDATED v4.1.2 NULL R4: 27th November 2009                             */
/*                                                                              */
/*   TESTING + VERIFICATION::                                                   */
/*     Files Cleaned, Nulled, Checked, Verified By:                             */
/*      -> FLIPMODE!                                                            */
/*     Decoded By:                                                              */
/*      -> FLIPMODE! + Unknown Decoder                                          */
/*     Tested By:                                                               */
/*      -> FLIPMODE!, LeetWolf, and 12 Anonymous Users...                       */
/*     WHMCS 4.1.2 Supplied By:                                                 */
/*      -> WHM CompleteShit Coder @ WHMCS.com                                   */
/*                                                                              */
/*                                                                              */
/*   IMPORTANT NOTE::                                                           */
/*   PLEASE NOTE THIS IS FOR TRIAL PURPOSES ONLY!                               */
/*                          LIKE IT? THEN BUY IT!                               */
/*                                                                              */
/* ========== ########## ========== ########## ========== ########## ========== */

class admininterface
{
	var $loginRequired = true;
	var $title = '';
	var $sidebar = '';
	var $icon = '';
	var $jscode = '';
	var $jquerycode = '';
	var $template = '';
	var $content = '';
	var $templatevars = array ();
	var $filename = '';
	var $rowLimit = 50;
	var $tablePagination = true;
	var $inClientsProfile = false;
	var $adminTemplate = 'original';
	var $exitmsg = '';
	function admininterface ($reqpermission)
	{
		global $CONFIG;
		global $adminpermsarray;
		global $licensing;
		global $remote_ip;
		$licensing->remoteCheck ();
		/* if ($licensing->getStatus () != 'Active')
		 {
			header ('Location: licenseerror.php?licenseerror=' . $licensing->getStatus ());
			exit ();
		} */

		if ($reqpermission)
		{
			$this->requiredPermission = $reqpermission;
		}
		else
		{
			$this->loginRequired = false;
		}

		require ROOTDIR . '/includes/smarty/Smarty.class.php';
		if ($this->loginRequired)
		{
			if ($CONFIG['DisableSessionIPCheck'])
			{
				$haship = '';
			}
			else
			{
				$haship = $remote_ip;
			}

			if ((!$_SESSION['adminid'] AND ($_COOKIE['WHMCSAdminID'] AND $_COOKIE['WHMCSAdminPW'])))
			{
				$result = select_query ('tbladmins', 'id,username,password', array ('id' => $_COOKIE['WHMCSAdminID']));
				$data = mysql_fetch_array ($result);
				$login_uid = $data['id'];
				$login_unm = $data['username'];
				$login_pwd = $data['password'];
				if (($login_uid AND $_COOKIE['WHMCSAdminPW'] == md5 ($login_uid . $login_pwd . $haship)))
				{
					$_SESSION['adminid'] = $_COOKIE['WHMCSAdminID'];
					$_SESSION['adminpw'] = $_COOKIE['WHMCSAdminPW'];
				}
			}

			if (!$_SESSION['adminid'])
			{
				header ('Location: login.php');
				exit ();
			}

			$result = select_query ('tbladmins', 'id,username,password,template', array ('id' => $_SESSION['adminid']));
			$data = mysql_fetch_array ($result);
			$login_uid = $data['id'];
			$login_unm = $data['username'];
			$login_pwd = $data['password'];
			if (($login_uid != $_SESSION['adminid'] OR $_SESSION['adminpw'] != md5 ($login_uid . $login_pwd . $haship)))
			{
				session_unset ();
				session_destroy ();
				header ('Location: login.php');
				exit ();
			}

			$this->adminTemplate = $data['template'];
			$result = select_query ('tbladminlog', 'id', 'lastvisit>=\'' . date ('Y-m-d H:i:s', mktime (date ('H'), date ('i') - 15, date ('s'), date ('m'), date ('d'), date ('Y'))) . '\' AND sessionid=\'' . session_id () . '\' AND logouttime=\'00000000000000\'');
			$data = mysql_fetch_array ($result);
			$adminlogid = $data['id'];
			if ($adminlogid)
			{
				update_query ('tbladminlog', array ('lastvisit' => 'now()'), array ('id' => $adminlogid));
			}
			else
			{
				full_query ('UPDATE tbladminlog SET logouttime=lastvisit WHERE adminusername=\'' . mysql_real_escape_string ($login_unm) . '\' AND logouttime=\'00000000000000\'');
				insert_query ('tbladminlog', array ('adminusername' => $login_unm, 'logintime' => 'now()', 'lastvisit' => 'now()', 'ipaddress' => $remote_ip, 'sessionid' => session_id ()));
			}
		}

		if ($this->requiredPermission)
		{
			$permid = array_search ($this->requiredPermission, $adminpermsarray);
			$result = select_query ('tbladmins', 'roleid', array ('id' => $_SESSION['adminid']));
			$data = mysql_fetch_array ($result);
			$roleid = $data['roleid'];
			$result = select_query ('tbladminperms', 'COUNT(*)', array ('roleid' => $roleid, 'permid' => $permid));
			$data = mysql_fetch_array ($result);
			$match = $data[0];
			if (!$match)
			{
				header ('' . 'Location: accessdenied.php?permid=' . $permid);
				exit ();
			}
		}

		$filename = $_SERVER['PHP_SELF'];
		$filename = substr ($filename, strrpos ($filename, '/'));
		$filename = str_replace (array ('/', '.php'), '', $filename);
		$this->filename = $filename;
		$this->rowLimit = $CONFIG['NumRecordstoDisplay'];
	}

	function requiredfiles ($reqfiles)
	{
		if (is_array ($reqfiles))
		{
			foreach ($reqfiles as $filename)
			{
				require ROOTDIR . '/includes/' . $filename . '.php';
			}
		}

	}

	function assign ($tplvar, $value = null)
	{
		$this->templatevars[$tplvar] = $value;
	}

	function clientsdropdown ($selectedval, $autosubmit = '', $fieldname = 'userid', $anyoption = '')
	{
		global $CONFIG;
		if ($CONFIG['DisableClientDropdown'])
		{
			return '<input type="text" name="' . $fieldname . '" value="' . $selectedval . '" size="10" />';
		}

		$clientgroups = getclientgroups ();
		$code = '<select name="' . $fieldname . '"';
		if ($autosubmit)
		{
			$code .= ' onChange="submit();"';
		}

		$code .= '>';
		if ($anyoption)
		{
			$code .= '<option value="">Any</option>';
		}

		$result = select_query ('tblclients', 'id,firstname,lastname,companyname,groupid', array ('status' => 'Active'), 'firstname` ASC,`lastname', 'ASC');
		while ($data = mysql_fetch_array ($result))
		{
			$selectid = $data['id'];
			$selectfirstname = $data['firstname'];
			$selectlastname = $data['lastname'];
			$selectcompanyname = $data['companyname'];
			$selectgroup = $data['groupid'];
			$selectfield = '';
			if ($CONFIG['ClientDropdownFormat'] == 1)
			{
				$selectfield .= '' . $selectfirstname . ' ' . $selectlastname;
				if ($selectcompanyname)
				{
					$selectfield .= '' . ' (' . $selectcompanyname . ')';
				}
			}
			else
			{
				if ($CONFIG['ClientDropdownFormat'] == 2)
				{
					if ($selectcompanyname)
					{
						$selectfield .= '' . $selectcompanyname . ' - ';
					}

					$selectfield .= '' . $selectfirstname . ' ' . $selectlastname;
				}
				else
				{
					$selectfield .= '' . '#' . $selectid . ' - ' . $selectfirstname . ' ' . $selectlastname;
					if ($selectcompanyname)
					{
						$selectfield .= '' . ' - ' . $selectcompanyname;
					}
				}
			}

			$code .= '<option value="' . $selectid . '"';
			if ($clientgroups[$selectgroup]['colour'])
			{
				$code .= ' style="background-color:' . $clientgroups[$selectgroup]['colour'] . '"';
			}

			if ($selectid == $selectedval)
			{
				$code .= ' selected';
			}

			$code .= '>' . $selectfield . '</option>' . '
';
		}

		$code .= '</select>';
		return $code;
	}

	function gettemplate ($template)
	{
		global $templates_compiledir;
		global $CONFIG;
		global $customadminpath;
		$smarty = new Smarty ();
		$smarty->template_dir = ROOTDIR . ('' . '/' . $customadminpath . '/templates/');
		$smarty->compile_dir = $templates_compiledir;
		foreach ($this->templatevars as $key => $value)
		{
			$smarty->assign ($key, $value);
		}

		$template_output = $smarty->fetch ($this->adminTemplate . ('' . '/' . $template . '.tpl'));
		return $template_output;
	}

	function display ()
	{
		global $templates_compiledir;
		global $CONFIG;
		global $customadminpath;
		$smarty = new Smarty ();
		$smarty->template_dir = ROOTDIR . ('' . '/' . $customadminpath . '/templates/');
		$smarty->compile_dir = $templates_compiledir;
		if ($this->inClientsProfile)
		{
			$this->title = 'Clients Profile';
			$this->sidebar = 'clients';
			$this->icon = 'clientsprofile';
		}

		$this->assign ('charset', $CONFIG['Charset']);
		$this->assign ('pagetitle', $this->title);
		$this->assign ('sidebar', $this->sidebar);
		$this->assign ('pageicon', $this->icon);
		$this->assign ('jquerycode', $this->jquerycode);
		$this->assign ('jscode', $this->jscode);
		$this->assign ('datepickerformat', str_replace (array ('DD', 'MM', 'YYYY'), array ('dd', 'mm', 'yy'), $CONFIG['DateFormat']));
		$result = select_query ('tbladmins', 'firstname,lastname,notes,supportdepts', array ('id' => $_SESSION['adminid']));
		$data = mysql_fetch_array ($result);
		$admin_username = $data['firstname'] . ' ' . $data['lastname'];
		$admin_notes = $data['notes'];
		$admin_supportdepts = $data['supportdepts'];
		$this->assign ('admin_username', ucfirst ($admin_username));
		$this->assign ('admin_notes', $admin_notes);
		$admins = '';
		$query = 'SELECT DISTINCT adminusername FROM tbladminlog WHERE lastvisit>=\'' . date ('Y-m-d H:i:s', mktime (date ('H'), date ('i') - 15, date ('s'), date ('m'), date ('d'), date ('Y'))) . '\' AND logouttime=\'0000-00-00\' ORDER BY lastvisit ASC';
		$result = full_query ($query);
		while ($data = mysql_fetch_array ($result))
		{
			$admins .= $data['adminusername'] . ', ';
		}

		$this->assign ('adminsonline', substr ($admins, 0, 0 - 2));
		if ($this->sidebar == 'support')
		{
			$ticketcounts = array ();
			$ticketcounts['open'] = $ticketcounts['answered'] = $ticketcounts['customerreply'] = $ticketcounts['onhold'] = $ticketcounts['inprogress'] = $ticketcounts['closed'] = 0;
			$query = 'SELECT status,COUNT(*) FROM tbltickets WHERE did IN (0' . $admin_supportdepts . '0) GROUP BY status';
			$result = mysql_query ($query);
			while ($data = mysql_fetch_array ($result))
			{
				$ticketcounts[str_replace ('-', '', str_replace (' ', '', strtolower ($data[0])))] = $data[1];
			}

			$ticketcounts['allactive'] = $ticketcounts['open'] + $ticketcounts['answered'] + $ticketcounts['customerreply'] + $ticketcounts['onhold'] + $ticketcounts['inprogress'];
			$ticketcounts['awaitingreply'] = $ticketcounts['open'] + $ticketcounts['customerreply'];
			$result = select_query ('tbltickets', 'COUNT(*)', 'status!=\'Closed\' AND flag=\'' . $_SESSION['adminid'] . '\'');
			$data = mysql_fetch_array ($result);
			$ticketcounts['myflagged'] = $data[0];
			if (!$ticketcounts['myflagged'])
			{
				$ticketcounts['myflagged'] = 0;
			}

			$this->assign ('ticketcounts', $ticketcounts);
		}

		foreach ($this->templatevars as $key => $value)
		{
			$smarty->assign ($key, $value);
		}

		if (checkpermission ('Sidebar Statistics', true))
		{
			$templatevars = array ();
			$query = 'SELECT COUNT(*) FROM tblorders INNER JOIN tblclients ON tblclients.id=tblorders.userid WHERE tblorders.status=\'Pending\'';
			$result = mysql_query ($query);
			$data = mysql_fetch_array ($result);
			$templatevars['orders']['pending'] = $data[0];
			$templatevars['clients']['active'] = $templatevars['clients']['inactive'] = $templatevars['clients']['closed'] = 0;
			$query = 'SELECT status,COUNT(*) FROM tblclients GROUP BY status';
			$result = mysql_query ($query);
			while ($data = mysql_fetch_array ($result))
			{
				$templatevars['clients'][strtolower ($data[0])] = $data[1];
			}

			$templatevars['services']['pending'] = $templatevars['services']['active'] = $templatevars['services']['suspended'] = $templatevars['services']['terminated'] = $templatevars['services']['cancelled'] = $templatevars['services']['fraud'] = 0;
			$query = 'SELECT domainstatus,COUNT(*) FROM tblhosting GROUP BY domainstatus';
			$result = mysql_query ($query);
			while ($data = mysql_fetch_array ($result))
			{
				$templatevars['services'][strtolower ($data[0])] = $data[1];
			}

			$templatevars['domains']['pending'] = $templatevars['domains']['active'] = $templatevars['domains']['pendingtransfer'] = $templatevars['domains']['expired'] = $templatevars['domains']['cancelled'] = $templatevars['domains']['fraud'] = 0;
			$query = 'SELECT status,COUNT(*) FROM tbldomains GROUP BY status';
			$result = mysql_query ($query);
			while ($data = mysql_fetch_array ($result))
			{
				$templatevars['domains'][str_replace (' ', '', strtolower ($data[0]))] = $data[1];
			}

			$query = 'SELECT COUNT(id) FROM tblinvoices WHERE status=\'Unpaid\'';
			$result = mysql_query ($query);
			$data = mysql_fetch_array ($result);
			$templatevars['invoices']['unpaid'] = $data[0];
			$query = 'SELECT COUNT(id) FROM tblinvoices WHERE status=\'Unpaid\' AND duedate<\'' . date ('Ymd') . '\'';
			$result = mysql_query ($query);
			$data = mysql_fetch_array ($result);
			$templatevars['invoices']['overdue'] = $data[0];
			$query = 'SELECT COUNT(*) FROM tbltickets WHERE status!=\'Closed\'';
			$result = mysql_query ($query);
			$data = mysql_fetch_array ($result);
			$templatevars['tickets']['active'] = $data[0];
			$query = 'SELECT COUNT(*) FROM tbltickets WHERE status=\'Open\' OR status=\'Customer-Reply\'';
			$result = mysql_query ($query);
			$data = mysql_fetch_array ($result);
			$templatevars['tickets']['awaitingreply'] = $data[0];
			$query = 'SELECT COUNT(*) FROM tbltickets WHERE status!=\'Closed\' AND flag=\'' . $_SESSION['adminid'] . '\'';
			$result = mysql_query ($query);
			$data = mysql_fetch_array ($result);
			$templatevars['tickets']['flagged'] = $data[0];
			$smarty->assign ('sidebarstats', $templatevars);
		}

		$smarty->display ($this->adminTemplate . '/header.tpl');
		if ($this->inClientsProfile)
		{
			$this->profileHeader ();
		}

		$content = $this->content;
		if ($this->template)
		{
			$content = $smarty->fetch ($this->adminTemplate . '/' . $this->template . '.tpl');
		}

		$content = preg_replace ('/(<form\\W[^>]*\\bmethod=(\'|"|)POST(\'|"|)\\b[^>]*>)/i', '\\1' . '
' . generate_token (), $content);
		if ($this->exitmsg)
		{
			$content = $this->exitmsg;
		}

		echo $content;
		if ($this->inClientsProfile)
		{
			echo '</div></div>';
		}

		$smarty->display ($this->adminTemplate . '/footer.tpl');
	}

	function displaypopup ()
	{
		global $CONFIG;
		$content = $this->content;
		$content = preg_replace ('/(<form\\W[^>]*\\bmethod=(\'|"|)POST(\'|"|)\\b[^>]*>)/i', '\\1' . '
' . generate_token (), $content);
		echo '<html>
<head>
<title>WHMCS v4.1.2<sup>r3</sup> by Flipmode! - ' . $this->title . '</title>
<meta http-equiv="Content-Type" content="text/html; charset=' . $CONFIG['Charset'] . '">
<link href="templates/' . $this->adminTemplate . '/style.css" rel="stylesheet" type="text/css">
</head>
<body style="margin:0px">

<table width="100%" bgcolor="#ffffff" cellpadding="15"><tr><td>

<h2>' . $this->title . '</h2>

' . $content . '

</td></tr></table>

</body>
</html>';
	}

	function tabs ($tabs, $firsttabhidden = '')
	{
		global $jquerycode;
		$jquerycode .= '$(".tabbox").css("display","none");
var selectedTab;
$(".tab").click(function(){
    var elid = $(this).attr("id");
    $(".tab").removeClass("tabselected");
    $("#"+elid).addClass("tabselected");
    ';
		if (!$firsttabhidden)
		{
			$jquerycode .= 'if (elid != selectedTab) {
        $(".tabbox").slideUp();
        $("#"+elid+"box").slideDown();
        selectedTab = elid;
    }
    ';
		}
		else
		{
			$jquerycode .= '$(".tabbox").slideUp();
    if (elid != selectedTab) {
        selectedTab = elid;
        $("#"+elid+"box").slideDown();
    } else {
        selectedTab = null;
        $(".tab").removeClass("tabselected");
    }
    ';
		}

		$jquerycode .= '$("#tab").val(elid.substr(3));
});
';
		if ((!$firsttabhidden OR $_REQUEST['tab']))
		{
			$tabnumber = 0;
			if ($_REQUEST['tab'])
			{
				$tabnumber = $_REQUEST['tab'];
			}

			$jquerycode .= 'selectedTab = "tab' . $tabnumber . '";
$("#tab' . $tabnumber . '").addClass("tabselected");
$("#tab' . $tabnumber . 'box").css("display","");';
		}

		$content = '<div id="tabs"><ul>';
		foreach ($tabs as $i => $tab)
		{
			$content .= '<li id="tab' . $i . '" class="tab"><a href="javascript:;">' . $tab . '</a></li>';
		}

		$content .= '</ul></div>
        ';
		return $content;
	}

	function sortabletableinit ($defaultsort, $defaultorder = 'ASC')
	{
		global $orderby;
		global $order;
		global $page;
		global $limit;
		$sortpage = $this->filename;
		if ($defaultsort == 'nopagination')
		{
			$this->tablePagination = false;
		}
		else
		{
			if (!$_SESSION[$sortpage . 'orderby'])
			{
				$_SESSION[$sortpage . 'orderby'] = $defaultsort;
			}

			if (!$_SESSION[$sortpage . 'order'])
			{
				$_SESSION[$sortpage . 'order'] = $defaultorder;
			}

			if ($_SESSION[$sortpage . 'orderby'] == $orderby)
			{
				if ($_SESSION[$sortpage . 'order'] == 'ASC')
				{
					$_SESSION[$sortpage . 'order'] = 'DESC';
				}
				else
				{
					$_SESSION[$sortpage . 'order'] = 'ASC';
				}
			}

			if ($orderby)
			{
				$_SESSION[$sortpage . 'orderby'] = $orderby;
			}

			$orderby = $_SESSION[$sortpage . 'orderby'];
			$order = $_SESSION[$sortpage . 'order'];
		}

		if (!$page)
		{
			$page = 0;
		}

		$limit = $this->rowLimit;
	}

	function sortabletable ($columns, $tabledata, $formurl = '', $formbuttons = '')
	{
		global $orderby;
		global $order;
		global $numrows;
		global $page;
		$pages = intval ($numrows / $this->rowLimit);
		++$pages;
		if ($this->tablePagination)
		{
			$content = '<form method="get" action="' . $_SERVER['PHP_SELF'] . '">
<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr>
<td width="50%" align="left">' . $numrows . ' Records Found, Page ' . ($page + 1) . ' of ' . $pages . '</td>
<td width="50%" align="right">Jump to Page: <select name="page" onchange="submit()">';
			$i = 1;
			while ($i <= $pages)
			{
				$newpage = $i - 1;
				$content .= '<option value="' . $newpage . '"';
				if ($page == $newpage)
				{
					$content .= ' selected';
				}

				$content .= '>' . $i . '</option>';
				++$i;
			}

			$content .= '</select> <input type="submit" value="Go" /></td>
</tr></table>
';
			foreach ($_REQUEST as $key => $value)
			{
				if (((($key != 'orderby' AND $key != 'page') AND $key != 'PHPSESSID') AND $value))
				{
					$content .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />
';
					continue;
				}
			}

			$content .= '</form>
';
		}

		if ($formurl)
		{
			$content .= '<form method="post" action="' . $formurl . '">';
		}

		$content .= '
<div class="tablebg">
<table class="datatable" width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>';
		foreach ($columns as $column)
		{
			if (is_array ($column))
			{
				$sortableheader = true;
				$columnid = $column[0];
				$columnname = $column[1];
			}
			else
			{
				$sortableheader = false;
				$columnid = '';
				$columnname = $column;
			}

			if (!$columnname)
			{
				$content .= '<th width="20"></th>';
				continue;
			}
			else
			{
				if ($columnname == 'checkall')
				{
					global $jquerycode;
					$jquerycode .= '$("#checkall").toggle(function () {
            $(".checkall").attr("checked","checked");
            },function () {
            $(".checkall").attr("checked","");
            })';
					$content .= '<th width="20"><input type="checkbox" id="checkall"></th>';
					continue;
				}
				else
				{
					$content .= '<th>';
					if ($sortableheader)
					{
						$content .= '<a href="' . $_SERVER['PHP_SELF'] . '?';
						foreach ($_REQUEST as $key => $value)
						{
							if ((($key != 'orderby' AND $key != 'PHPSESSID') AND $value))
							{
								$content .= '' . $key . '=' . $value . '&';
								continue;
							}
						}

						$content .= 'orderby=' . $columnid . '">';
					}

					$content .= $columnname;
					if ($sortableheader)
					{
						$content .= '</a>';
						if ($orderby == $columnid)
						{
							$content .= ' <img src="images/' . strtolower ($order) . '.gif" class="absmiddle" />';
						}
					}

					$content .= '</th>';
					continue;
				}

				continue;
			}
		}

		$content .= '</tr>
';
		$totalcols = count ($columns);
		if (is_array ($tabledata))
		{
			foreach ($tabledata as $tablevalues)
			{
				if ($tablevalues[0] == 'dividingline')
				{
					$content .= '<tr><td colspan="' . $totalcols . '" style="background-color:#efefef;"><div align="left"><b>' . $tablevalues[1] . '</b></div></td></tr>
';
					continue;
				}
				else
				{
					$content .= '<tr>';
					foreach ($tablevalues as $tablevalue)
					{
						$content .= '<td>' . $tablevalue . '</td>';
					}

					$content .= '</tr>
';
					continue;
				}
			}
		}
		else
		{
			$content .= '<tr><td colspan="' . $totalcols . '">No Records Found</td></tr>
';
		}

		$content .= '</table>
</div>
';
		if ($formbuttons)
		{
			$content .= '<p>With Selected: ' . $formbuttons . '</p>
</form>
';
		}

		if ($this->tablePagination)
		{
			$content .= '<p align="center">';
			if (0 < $page)
			{
				$prevoffset = $page - 1;
				$content .= '<a href="' . $_SERVER['PHP_SELF'] . '?';
				foreach ($_REQUEST as $key => $value)
				{
					if (((($key != 'orderby' AND $key != 'page') AND $key != 'PHPSESSID') AND $value))
					{
						$content .= '' . $key . '=' . $value . '&';
						continue;
					}
				}

				$content .= '' . 'page=' . $prevoffset . '">&laquo; Previous Page</a> &nbsp; ';
			}
			else
			{
				$content .= '&laquo; Previous Page &nbsp;
';
			}

			if (($page * $this->rowLimit + $this->rowLimit) / $this->rowLimit == $pages)
			{
				$content .= 'Next Page &raquo;';
			}
			else
			{
				$newoffset = $page + 1;
				$content .= '<a href="' . $_SERVER['PHP_SELF'] . '?';
				foreach ($_REQUEST as $key => $value)
				{
					if (((($key != 'orderby' AND $key != 'page') AND $key != 'PHPSESSID') AND $value))
					{
						$content .= '' . $key . '=' . $value . '&';
						continue;
					}
				}

				$content .= '' . 'page=' . $newoffset . '">Next Page &raquo;</a>';
			}

			$content .= '</p>';
		}

		return $content;
	}

	function profileheader ()
	{
		global $CONFIG;
		$tabarray = array ();
		$tabarray['clientssummary'] = 'Summary';
		$tabarray['clientsprofile'] = 'Profile';
		$tabarray['clientscontacts'] = 'Contacts';
		$tabarray['clientshosting'] = 'Products/Services';
		$tabarray['clientsdomains'] = 'Domains';
		$tabarray['clientsbillableitems'] = 'Billable Items';
		$tabarray['clientsinvoices'] = 'Invoices';
		$tabarray['clientsquotes'] = 'Quotes';
		$tabarray['clientstransactions'] = 'Transactions';
		$tabarray['clientsemails'] = 'Emails';
		$tabarray['clientsnotes'] = 'Notes';
		echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="get">
<p>Active Client: ';
		if ($CONFIG['DisableClientDropdown'])
		{
			$result = select_query ('tblclients', '', array ('id' => $GLOBALS['userid']));
			$data = mysql_fetch_array ($result);
			$selectfirstname = $data['firstname'];
			$selectlastname = $data['lastname'];
			$selectcompanyname = $data['companyname'];
			echo $selectfirstname . ' ' . $selectlastname;
			if ($selectcompanyname)
			{
				echo '' . ' (' . $selectcompanyname . ')';
			}
		}
		else
		{
			echo $this->clientsDropDown ($GLOBALS['userid'], true);
			echo ' <input type="submit" value="Go">';
		}

		echo '</p>
</form>';
		echo '
<div id="clienttabs">
<ul>';
		foreach ($tabarray as $link => $name)
		{
			if ($link == $this->filename)
			{
				$class = 'tabselected';
			}
			else
			{
				$class = 'tab';
			}

			echo '<li class="' . $class . '"><a href="' . $link . '.php?userid=' . $_GET['userid'] . '">' . $name . '</a></li>';
		}

		echo '</ul>
</div>
<div id="tab0box" class="tabbox">
  <div id="tab_content" style="text-align:left;">';
	}

	function gracefulexit ($msg)
	{
		$this->exitmsg = '<p>' . $msg . '</p>';
	}
}

function checkpermission ($action, $noredirect = '')
{
	global $adminpermsarray;
	$permid = array_search ($action, $adminpermsarray);
	$result = select_query ('tbladmins', 'roleid', array ('id' => $_SESSION['adminid']));
	$data = mysql_fetch_array ($result);
	$roleid = $data['roleid'];
	$result = select_query ('tbladminperms', 'COUNT(*)', array ('roleid' => $roleid, 'permid' => $permid));
	$data = mysql_fetch_array ($result);
	$match = $data[0];
	if ($noredirect)
	{
		if ($match)
		{
			return true;
		}

		return false;
	}

	if (!$match)
	{
		header ('' . 'Location: accessdenied.php?permid=' . $permid);
		exit ();
	}

}

function infobox ($title, $description)
{
	global $infobox;
	$infobox = '' . '<div class="infobox"><strong>' . $title . '</strong><br>' . $description . '</div>';
}

function getadminname ()
{
	$result = select_query ('tbladmins', 'firstname,lastname', array ('id' => $_SESSION['adminid']));
	$data = mysql_fetch_array ($result);
	$adminname = $data['firstname'] . ' ' . $data['lastname'];
	return $adminname;
}

function getadminhomestats ()
{
	global $currency;
	$stats = array ();
	$currency = getcurrency (0, 1);
	$result = full_query ('SELECT SUM((amountin-fees-amountout)/rate) FROM tblaccounts WHERE date LIKE \'' . date ('Y-m-d') . '%\'');
	$data = mysql_fetch_array ($result);
	$todaysincome = formatcurrency ($data[0]);
	$stats['income']['today'] = $todaysincome;
	$result = full_query ('SELECT SUM((amountin-fees-amountout)/rate) FROM tblaccounts WHERE date LIKE \'' . date ('Y-m-') . '%\'');
	$data = mysql_fetch_array ($result);
	$todaysincome = formatcurrency ($data[0]);
	$stats['income']['thismonth'] = $todaysincome;
	$result = full_query ('SELECT SUM((amountin-fees-amountout)/rate) FROM tblaccounts WHERE date LIKE \'' . date ('Y-') . '%\'');
	$data = mysql_fetch_array ($result);
	$todaysincome = formatcurrency ($data[0]);
	$stats['income']['thisyear'] = $todaysincome;
	$result = full_query ('SELECT SUM(total)-COALESCE(SUM((SELECT SUM(amountin) FROM tblaccounts WHERE tblaccounts.invoiceid=tblinvoices.id)),0) FROM tblinvoices WHERE tblinvoices.status=\'Unpaid\' AND duedate<\'' . date ('Ymd') . '\'');
	$data = mysql_fetch_array ($result);
	$overdueinvoices = $data[0];
	$stats['invoices']['overduebalance'] = $data[1];
	$result = full_query ('SELECT COUNT(*) FROM tblcancelrequests INNER JOIN tblhosting ON tblhosting.id=tblcancelrequests.relid WHERE (tblhosting.domainstatus!=\'Cancelled\' AND tblhosting.domainstatus!=\'Terminated\')');
	$data = mysql_fetch_array ($result);
	$stats['cancellations']['pending'] = $data[0];
	$stats['orders']['today']['active'] = $stats['orders']['today']['fraud'] = $stats['orders']['today']['pending'] = $stats['orders']['today']['cancelled'] = 0;
	$query = 'SELECT status,COUNT(*) FROM tblorders WHERE date LIKE \'' . date ('Y-m-d') . '%\' GROUP BY status';
	$result = mysql_query ($query);
	while ($data = mysql_fetch_array ($result))
	{
		$stats['orders']['today'][strtolower ($data[0])] = $data[1];
	}

	$stats['orders']['today']['total'] = $stats['orders']['today']['active'] + $stats['orders']['today']['fraud'] + $stats['orders']['today']['pending'] + $stats['orders']['today']['cancelled'];
	$stats['orders']['yesterday']['active'] = $stats['orders']['yesterday']['fraud'] = $stats['orders']['yesterday']['pending'] = $stats['orders']['yesterday']['cancelled'] = 0;
	$query = 'SELECT status,COUNT(*) FROM tblorders WHERE date LIKE \'' . date ('Y-m-d', mktime (0, 0, 0, date ('m'), date ('d') - 1, date ('Y'))) . '%\' GROUP BY status';
	$result = mysql_query ($query);
	while ($data = mysql_fetch_array ($result))
	{
		$stats['orders']['yesterday'][strtolower ($data[0])] = $data[1];
	}

	$stats['orders']['yesterday']['total'] = $stats['orders']['yesterday']['active'] + $stats['orders']['yesterday']['fraud'] + $stats['orders']['yesterday']['pending'] + $stats['orders']['yesterday']['cancelled'];
	$query = 'SELECT COUNT(*) FROM tblorders WHERE date LIKE \'' . date ('Y-m-') . '%\'';
	$result = mysql_query ($query);
	$data = mysql_fetch_array ($result);
	$stats['orders']['thismonth']['total'] = $data[0];
	$query = 'SELECT COUNT(*) FROM tblorders WHERE date LIKE \'' . date ('Y-') . '%\'';
	$result = mysql_query ($query);
	$data = mysql_fetch_array ($result);
	$stats['orders']['thisyear']['total'] = $data[0];
	$stats['tickets']['open'] = $stats['tickets']['answered'] = $stats['tickets']['customerreply'] = $stats['tickets']['onhold'] = $stats['tickets']['inprogress'] = $stats['tickets']['closed'] = 0;
	$query = 'SELECT status,COUNT(*) FROM tbltickets GROUP BY status';
	$result = mysql_query ($query);
	while ($data = mysql_fetch_array ($result))
	{
		$stats['tickets'][str_replace ('-', '', str_replace (' ', '', strtolower ($data[0])))] = $data[1];
	}

	$query = 'SELECT COUNT(*) FROM tbltodolist WHERE status!=\'Completed\' AND status!=\'Postponed\' AND duedate<=\'' . date ('Y-m-d') . '\'';
	$result = mysql_query ($query);
	$data = mysql_fetch_array ($result);
	$stats['todoitems']['due'] = $data[0];
	$query = 'SELECT COUNT(*) FROM tblnetworkissues WHERE status!=\'Scheduled\' AND status!=\'Resolved\'';
	$result = mysql_query ($query);
	$data = mysql_fetch_array ($result);
	$stats['networkissues']['open'] = $data[0];
	$result = select_query ('tblbillableitems', 'COUNT(*)', array ('invoicecount' => '0'));
	$data = mysql_fetch_array ($result);
	$stats['billableitems']['uninvoiced'] = $data[0];
	$result = select_query ('tblquotes', 'COUNT(*)', array ('validuntil' => array ('sqltype' => '>', 'value' => date ('Ymd'))));
	$data = mysql_fetch_array ($result);
	$stats['quotes']['valid'] = $data[0];
	return $stats;
}

$adminpermsarray = array (1 => 'Main Homepage', 2 => 'Sidebar Statistics', 3 => 'My Account', 4 => 'List Clients', 5 => 'List Services', 6 => 'List Addons', 7 => 'List Domains', 8 => 'Add New Client', 9 => 'Edit Clients Details', 10 => 'View Credit Card Details', 11 => 'View Clients Products/Services', 12 => 'Edit Clients Products/Services', 13 => 'Delete Clients Products/Services', 14 => 'Perform Server Operations', 15 => 'View Clients Domains', 16 => 'Edit Clients Domains', 17 => 'Delete Clients Domains', 95 => 'Manage Clients Files', 18 => 'View Clients Notes', 19 => 'Add/Edit/Delete Client Notes', 20 => 'Delete Client', 21 => 'Mass Mail', 22 => 'View Cancellation Requests', 23 => 'Manage Affiliates', 24 => 'View Orders', 25 => 'Delete Order', 26 => 'View Order Details', 27 => 'Add New Order', 28 => 'List Transactions', 94 => 'View Income Totals', 29 => 'Add Transaction', 30 => 'Edit Transaction', 31 => 'Delete Transaction', 33 => 'List Invoices', 34 => 'Create Invoice', 35 => 'Manage Invoice', 36 => 'Delete Invoice', 92 => 'Refund Invoice Payments', 89 => 'View Billable Items', 90 => 'Manage Billable Items', 37 => 'Offline Credit Card Processing', 32 => 'View Gateway Log', 85 => 'Manage Quotes', 38 => 'Support Center Overview', 39 => 'Manage Announcements', 40 => 'Manage Knowledgebase', 41 => 'Manage Downloads', 84 => 'Manage Network Issues', 42 => 'List Support Tickets', 82 => 'View Flagged Tickets', 43 => 'Open New Ticket', 93 => 'Delete Ticket', 44 => 'Manage Predefined Replies', 45 => 'View Reports', 88 => 'CSV Downloads', 46 => 'Addon Modules', 47 => 'Link Tracking', 48 => 'Browser', 49 => 'Calendar', 50 => 'To-Do List', 51 => 'WHOIS Lookups', 52 => 'Domain Resolver Checker', 53 => 'View Integration Code', 54 => 'WHM Import Script', 55 => 'Database Status', 56 => 'System Cleanup Operations', 57 => 'View PHP Info', 58 => 'View Activity Log', 59 => 'View Admin Log', 60 => 'View Email Message Log', 61 => 'View Ticket Mail Import Log', 62 => 'View WHOIS Lookup Log', 63 => 'Configure General Settings', 64 => 'Configure Administrators', 65 => 'Configure Admin Roles', 91 => 'Configure Client Groups', 66 => 'Configure Servers', 67 => 'Configure Automation Settings', 86 => 'Configure Currencies', 68 => 'Configure Payment Gateways', 69 => 'Configure Tax Setup', 70 => 'Configure Email Templates', 71 => 'Configure Products/Services', 72 => 'Configure Product Addons', 73 => 'Configure Promotions', 74 => 'Configure Domain Pricing', 75 => 'Configure Support Departments', 76 => 'Configure Spam Control', 77 => 'Configure Ban Control', 78 => 'Configure Domain Registrars', 79 => 'Configure Fraud Protection', 80 => 'Configure Custom Client Fields', 87 => 'Configure Security Questions', 83 => 'Configure Database Backups', 81 => 'API Access');
?>